######################################################################
# @author      : bidaya0 (bidaya0@$HOSTNAME)
# @file        : vulnerability_status
# @created     : Friday Aug 27, 2021 15:34:34 CST
#
# @description :
######################################################################



from dongtai_common.models.vulnerablity import IastVulnerabilityStatus
from dongtai_common.endpoint import R
from dongtai_common.endpoint import UserEndPoint
from django.forms.models import model_to_dict
from dongtai_web.utils import extend_schema_with_envcheck, get_response_serializer
from django.utils.translation import gettext_lazy as _
from rest_framework import serializers


class VulnerabilityStatusSerializer(serializers.Serializer):
    id = serializers.IntegerField()
    name = serializers.CharField()
    name_en = serializers.CharField()
    name_zh = serializers.CharField()

    class Meta:
        model = IastVulnerabilityStatus
        fields = ['id', 'name', 'name_en', 'name_zh']


_ResponseSerializer = get_response_serializer(
    VulnerabilityStatusSerializer(many=True))


class VulnerabilityStatusView(UserEndPoint):
    @extend_schema_with_envcheck(
        [],
        [],
        [{
            'name':
            _('Get data sample'),
            'description':
            _("The aggregation results are programming language, risk level, vulnerability type, project"
              ),
            'value': {
                "status":
                201,
                "msg":
                "success",
                "data": [{
                    "id": 1,
                    "name": "Pending",
                    "name_en": "Pending",
                    "name_zh": "\u5f85\u9a8c\u8bc1"
                }, {
                    "id": 2,
                    "name": "Verifying",
                    "name_en": "Verifying",
                    "name_zh": "\u9a8c\u8bc1\u4e2d"
                }, {
                    "id": 3,
                    "name": "Confirmed",
                    "name_en": "Confirmed",
                    "name_zh": "\u5df2\u786e\u8ba4"
                }, {
                    "id": 4,
                    "name": "Ignore",
                    "name_en": "Ignore",
                    "name_zh": "\u5df2\u5ffd\u7565"
                }, {
                    "id": 5,
                    "name": "Solved",
                    "name_en": "Solved",
                    "name_zh": "\u5df2\u5904\u7406"
                }]
            }
        }],
        tags=[_('Vulnerability')],
        summary=_("Vulnerability Status List"),
        description=
        _("""Vulnerability status list, which contains the optional status of vulnerabilities. 
            When calling the vulnerability status modification API, please obtain the vulnerability status data from this API first."""
          ),
        response_schema=_ResponseSerializer
    )
    def get(self, request):
        status = IastVulnerabilityStatus.objects.all()
        return R.success(data=[model_to_dict(_) for _ in status])
